package com.xpm.base;

import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;

import java.util.List;

public abstract class BaseDiffAdapter<T,VB extends ViewBinding> extends RecyclerView.Adapter<BaseAdapter.BaseViewHolder<VB>> {
    private final DiffUtil.ItemCallback<T> diffCallback;

    public BaseDiffAdapter(DiffUtil.ItemCallback<T> diffCallback) {
        this.diffCallback = diffCallback;
    }

    public void setData(List<T> newData) {
        DiffUtil.DiffResult result = DiffUtil.calculateDiff(new DiffUtil.Callback() {
            @Override
            public int getOldListSize() {
                return 0;
            }

            @Override
            public int getNewListSize() {
                return 0;
            }

            @Override
            public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
                return false;
            }

            @Override
            public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
                return false;
            }
            // 实现 DiffUtil 的对比方法
        });
        result.dispatchUpdatesTo(this);
    }


}
